package com.atguigu.srb.sms.util;

import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 手机短信属性配置类
 * 专门用来读取配置文件配置项的值
 * @author bing  @create 2021/4/9-下午1:49
 */
@Data
@Component
@ConfigurationProperties(prefix = "aliyun.sms") // 在配置文件中的前缀
public class SmsProperties implements InitializingBean {
    // 根据 application.yml 中配置的定义属性
    private String regionId;
    private String keyId;
    private String keySecret;
    private String templateCode;
    private String signName;

    public static String REGION_Id;
    public static String KEY_ID;
    public static String KEY_SECRET;
    public static String TEMPLATE_CODE;
    public static String SIGN_NAME;

    /**
     * implements InitializingBean 的方法
     * 当配置属性设置完成之后自动调用此方法
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        REGION_Id = regionId;
        KEY_ID = keyId;
        KEY_SECRET = keySecret;
        TEMPLATE_CODE = templateCode;
        SIGN_NAME = signName;
    }
}

